package com.tianye.lc.activity;

import android.content.Intent;
import android.graphics.Rect;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.tianye.lc.R;
import com.tianye.lc.adapter.MainRecyclerAdapter;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends BaseActivity {
    private RecyclerView recycler;
    private MainRecyclerAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initTitle();
        initView();
        initData();

    }

    @Override
    protected int getTitleLayout() {
        return R.layout.title_view_1;
    }

    private void initTitle() {
        findViewById(R.id.right_iv).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this, AddOrShowOrEditActivity.class));
            }
        });
        TextView title = (TextView) findViewById(R.id.title_tv);
        title.setText("植物");
    }

    private void initView() {
        recycler = (RecyclerView) findViewById(R.id.recycler);
        recycler.setLayoutManager(new LinearLayoutManager(this));
        recycler.addItemDecoration(new RecyclerView.ItemDecoration() {
            @Override
            public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
                //设定底部边距为1px
                outRect.set(0, 0, 0, 1);
            }
        });
        recycler.setHasFixedSize(true);

        adapter = new MainRecyclerAdapter(this);
        recycler.setAdapter(adapter);
        adapter.setData(getRecyclerData());
    }

    private void initData() {

    }

    private List<String> getRecyclerData() {
        List<String> data = new ArrayList<String>();
        data.add("Rose（月季、玫瑰、蔷薇）");
        data.add("浴花谷月季资料");
        return data;
    }
}
